#include "SDL.h"
#include "SDL_image.h"

#include "stdio.h"

#include <iostream>
#include <fstream>
#include <string> 
using namespace std;

#include "image.h"
#include "data.h"





bool loadTextures()
{
	if (terrain[0]=loadImage("data/sprites/terrain/grass.jpg") )
		return true;
	else 
		return false;
}

bool loadBackgrounds()
{
	if (background[0]=loadImage("data/sprites/background/scenery.jpg") )
		return true;
	else 
		return false;
}

bool loadCharacters()
{
	// define the character clips of character sprites
		charClip[0].x=0;
		charClip[0].y=0;
		charClip[0].w=50;
		charClip[0].h=100;

		charClip[1].x=50;
		charClip[1].y=0;
		charClip[1].w=50;
		charClip[1].h=100;

		charClip[2].x=100;
		charClip[2].y=0;
		charClip[2].w=50;
		charClip[2].h=100;

		charClip[3].x=150;
		charClip[3].y=0;
		charClip[3].w=50;
		charClip[3].h=100;

	if (character[0]=loadImage("data/sprites/character/0.bmp") )
		return true;
	else 
		return false;
}

mapData loadMap(std::string mapName)
{
  mapData mapTemp;
  string line;
  ifstream myFile(mapName.c_str());
  if (myFile.is_open())
  {
    while (! myFile.eof() )
    {
		getline (myFile,line);
		mapTemp.id=atoi(line.c_str());
		getline (myFile,line);
		mapTemp.name=line;
		getline (myFile,line);
		mapTemp.width=atoi(line.c_str());
		getline (myFile,line);
		mapTemp.height=atoi(line.c_str());
		getline (myFile,line);
		mapTemp.background=atoi(line.c_str());
		for (int i=0;i<mapTemp.width*mapTemp.height;i++)
		{
			getline (myFile,line);
			mapTemp.terrain[i]=atoi(line.c_str());
		}
		getline (myFile,line);
		mapTemp.warpNum=atoi(line.c_str());
		//if (mapTemp.warpNum>0)
		//{
		//	for (int i=0;i<mapTemp.warpNum;i++)
		//	{
		//	getline (myFile,line);
		//	//mapTemp.terrain[i]=atoi(line.c_str());
		//	}
		//}
    }
    myFile.close();
  }
  return mapTemp;
}


